package cn.magicman.demo;

import java.util.concurrent.*;

public class ThreadPoolDemo2 {

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService pool = Executors.newFixedThreadPool(5);

        Callable<String> task1 = () -> {
            Thread.sleep(1000);
            return "111";
        };

        Thread.sleep(5000);

        Callable<String> task2 = () -> {
            Thread.sleep(1000);
            return "222";
        };


        Thread.sleep(5000);

        Callable<String> task3 = () -> {
            Thread.sleep(1000);
            return "333";
        };

        Future<String> result1 = pool.submit(task1);
        Future<String> result2 = pool.submit(task2);
        Future<String> result3 = pool.submit(task3);

        String s1 = result1.get();
        System.out.println(s1);
        String s2 = result2.get();
        System.out.println(s2);
        String s3 = result3.get();
        System.out.println(s3);

        String s = s1 + s2 + s3;
        System.out.println(s);
    }
}
